|
1
|
|
|
/*global document, window, $ */ |
|
2
|
|
|
|
|
3
|
|
|
import {Devtool} from './devtool/Devtool' |
|
4
|
|
|
|
|
5
|
|
|
import EditorInputs from './modules/EditorInputs' |
|
6
|
|
|
import EditorBlock from './modules/EditorBlock' |
|
7
|
|
|
import EditorFiles from './modules/EditorFiles' |
|
8
|
|
|
import EditorSave from './modules/EditorSave' |
|
9
|
|
|
import EditorJson from './modules/EditorJson' |
|
10
|
|
|
import EditorManager from './modules/EditorManager' |
|
11
|
|
|
import EditorAutocomplete from './modules/EditorAutocomplete' |
|
12
|
|
|
import EditorReload from './modules/EditorReload' |
|
13
|
|
|
|
|
14
|
|
|
var htmlTag = document.querySelector('html') |
|
15
|
|
|
window.CONFIG = JSON.parse(htmlTag.getAttribute('data-config')) |
|
16
|
|
|
// window.json = JSON.parse(unescape(htmlTag.getAttribute('data-json').replace(/"/g, '\"'))) |
|
17
|
|
|
var j = htmlTag.getAttribute('data-json') |
|
18
|
|
|
j = j.replace(/"/g, '"') |
|
19
|
|
|
j = unescape(j) |
|
20
|
|
|
j = j.replace(/\%27/g, '\'') |
|
21
|
|
|
window.json = JSON.parse(j) |
|
22
|
|
|
window.Locales = JSON.parse(htmlTag.getAttribute('data-locales')) |
|
23
|
|
|
|
|
24
|
|
|
class Engine { |
|
25
|
|
|
|
|
26
|
|
|
constructor() { |
|
27
|
|
|
this._blocks = new EditorBlock() |
|
28
|
|
|
this._inputs = new EditorInputs() |
|
29
|
|
|
this._files = new EditorFiles() |
|
30
|
|
|
this._save = new EditorSave() |
|
31
|
|
|
this._manager = new EditorManager() |
|
32
|
|
|
this._autocomplete = new EditorAutocomplete() |
|
33
|
|
|
this._dev = new Devtool() |
|
34
|
|
|
|
|
35
|
|
|
this.json = EditorJson.instance |
|
36
|
|
|
|
|
37
|
|
|
this._bindEvents() |
|
38
|
|
|
|
|
39
|
|
|
this.table = null |
|
40
|
|
|
$(document).ready(() => { |
|
41
|
|
|
this.table = $('#navigation-list').DataTable({ |
|
42
|
|
|
//"order": [[ 3, 'desc' ]], |
|
43
|
|
|
'pageLength': 50, |
|
44
|
|
|
'autoWidth': false |
|
45
|
|
|
}) |
|
46
|
|
|
}) |
|
47
|
|
|
|
|
48
|
|
|
var abeReady = new Event('abeReady'); |
|
|
|
|
|
|
49
|
|
|
document.dispatchEvent(abeReady); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
inject() { |
|
53
|
|
|
var findComments = function(el) { |
|
54
|
|
|
var arr = [] |
|
55
|
|
|
for(var i = 0; i < el.childNodes.length; i++) { |
|
56
|
|
|
var node = el.childNodes[i] |
|
57
|
|
|
if(node.nodeType === 8) { |
|
58
|
|
|
arr.push(node) |
|
59
|
|
|
} else { |
|
60
|
|
|
arr.push.apply(arr, findComments(node)) |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
return arr |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
var commentNodes = findComments(document) |
|
67
|
|
|
|
|
68
|
|
|
Array.prototype.forEach.call(commentNodes, (comment) => { |
|
69
|
|
|
if (comment.nodeValue.indexOf('[pageHTML]') > -1) { |
|
70
|
|
|
var base = comment.data |
|
71
|
|
|
if(typeof base !== 'undefined' && base !== null) { |
|
72
|
|
|
base = base.replace(/\[pageHTML\]/g, '') |
|
73
|
|
|
base = base.replace(/<ABE!--/g, '<!--').replace(/--ABE>/g, '-->') |
|
74
|
|
|
EditorReload.instance.inject(base) |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
}) |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
_bindEvents() { |
|
81
|
|
|
|
|
82
|
|
|
this._blocks.onNewBlock(() => { |
|
83
|
|
|
this._files.rebind() |
|
84
|
|
|
this._inputs.rebind() |
|
85
|
|
|
}) |
|
86
|
|
|
|
|
87
|
|
|
this._manager.remove((el) => { |
|
88
|
|
|
this.table.row($(el)).remove().draw() |
|
89
|
|
|
}) |
|
90
|
|
|
|
|
91
|
|
|
this._inputs.onReload(() => { |
|
92
|
|
|
this._save.serializeForm() |
|
93
|
|
|
EditorReload.instance.reload() |
|
94
|
|
|
}) |
|
95
|
|
|
|
|
96
|
|
|
this._autocomplete.onReload(() => { |
|
97
|
|
|
EditorReload.instance.reload() |
|
98
|
|
|
}) |
|
99
|
|
|
|
|
100
|
|
|
this._inputs.onBlur(() => { |
|
101
|
|
|
this._save.serializeForm() |
|
102
|
|
|
}) |
|
103
|
|
|
|
|
104
|
|
|
this._blocks.onRemoveBlock(() => { |
|
105
|
|
|
this._inputs.rebind() |
|
106
|
|
|
this._save.serializeForm() ///**************************************** HOOLA |
|
107
|
|
|
}) |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
var engine = new Engine() |
|
112
|
|
|
window.abe = { |
|
113
|
|
|
save: engine._save, |
|
114
|
|
|
json: engine.json, |
|
115
|
|
|
inputs: engine._inputs, |
|
116
|
|
|
files: engine._files, |
|
117
|
|
|
blocks: engine._blocks, |
|
118
|
|
|
autocomplete: engine._autocomplete, |
|
119
|
|
|
editorReload: EditorReload |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
123
|
|
|
if(document.querySelector('#page-template')) engine.inject() |
|
|
|
|
|
|
124
|
|
|
}) |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.